package com.zjw.zy.coreui.fragment.holder

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.zjw.zy.R
import com.zjw.zy.base.BaseViewHolder
import com.zjw.zy.bean.Tip
import com.zjw.zy.ext.dateString
import com.zjw.zy.utils.ResourcesUtils

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2022/11/2 13:28
 * @description：
 */
class TipHolder(item: View) : BaseViewHolder<Tip>(item) {
    companion object {
        const val FINISH_EVENT = "FINISH_EVENT"
        const val DETAIL_EVENT = "DETAIL_EVENT"
    }

    private val finish: ImageView by lazy { findViewById(R.id.tip_holder_finish) }
    private val tip: TextView by lazy { findViewById(R.id.tip_holder_tip) }
    private val date: TextView by lazy { findViewById(R.id.tip_holder_date) }
    private val tag: TextView by lazy { findViewById(R.id.tip_holder_tag) }
    private val details: ImageView by lazy { findViewById(R.id.tip_holder_detail) }

    override fun onBindListener() {
        finish.setOnClickListener {
            if (data.isDone) {
                return@setOnClickListener
            }
            finish.isActivated = true
            mListener?.onCallbackOtherEvent(FINISH_EVENT, super.getData())
        }

        details.setOnClickListener {
            mListener?.onCallbackOtherEvent(DETAIL_EVENT, super.getData())
        }
    }

    override fun onBindData(data: Tip?) {
        data?.let {
            tip.text = it.tip
            date.text = it.time.dateString()
            finish.isActivated = data.isDone
            tag.text = it.tag
            if (data.isPast) {
                //过期任务，标红处理
                tip.setTextColor(ResourcesUtils.getColor(R.color.tip_past_tip_color))
            } else {
                tip.setTextColor(ResourcesUtils.getColor(R.color.tip_plan_tip_color))
            }
        }
    }
}